<template>
  <div v-loading="loading" class="order_detail" element-loading-text="加载中...">
    <div v-if="orderDetail" class="header">
      <div class="order_detail_header_status">
        <div class="order_number_module">
          <span>{{ orderDetail.code }}</span
          >&nbsp;
          <span>{{ orderDetail.orderType }}</span>
        </div>
        <div class="status">
          <HStatus v-if="orderDetail.status === 1" type="warning">承接</HStatus>
          <HStatus v-if="orderDetail.status === 2" type="warning">发布</HStatus>
          <HStatus v-if="orderDetail.status === 3" type="info">取消</HStatus>
          <HStatus v-if="orderDetail.status === 4" type="success">确认完工</HStatus>
          <HStatus v-if="orderDetail.status === 5" type="success">部门完工</HStatus>
          <HStatus v-if="orderDetail.status === 6">已结算</HStatus>
          <HStatus v-if="orderDetail.status === 7" type="warning">登记</HStatus>
          <HStatus v-if="orderDetail.overinsured" type="info">{{
            orderDetail.overinsured ? '保外' : ''
          }}</HStatus>
          <HStatus v-if="orderDetail.overinsured == false"
            >在保{{ orderDetail.warrantyDay }}天</HStatus
          >
        </div>
      </div>
    </div>
    <div v-if="orderDetail" class="body">
      <div class="content_container">
        <div class="content">
          <div class="user_network_info">
            <div class="user_info">
              <user-info :order-detail="orderDetail" />
            </div>
            <div class="network_info">
              <network-info :order-detail="orderDetail" />
            </div>
          </div>
          <div class="order_info">
            <order-info :order-detail="orderDetail" />
          </div>
          <!--设备信息-->
          <commodity :order-id="orderDetail.id" />
        </div>
        <!-- <div class="expand_collapse" :style="{ transform: `translate(${isShowSideBar ? 100 : 0}%, 100%)` }">
          <el-tooltip content="收起" placement="left" v-if="isShowSideBar">
            <span class="show_btn_r" @click="isShowSideBar = false">
              <el-icon>
                <DArrowRight />
              </el-icon>
            </span>
          </el-tooltip>
          <el-tooltip content="展开" placement="left" v-else>
            <span class="show_btn_l" @click="isShowSideBar = true">
              <el-icon>
                <DArrowLeft />
              </el-icon>
            </span>
          </el-tooltip>
        </div> -->
      </div>
      <!-- <div class="sidebar" v-if="isShowSideBar && route.params.id">
        <operation-log ref="operationLogRef" :workId="route.params.id" />
      </div> -->
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref, watch } from 'vue'
  import { useRoute } from 'vue-router'
  import { getHistoryDetail } from '@/api/order'
  import { ElMessage } from 'element-plus'
  import { DArrowLeft, DArrowRight } from '@element-plus/icons-vue'
  import UserInfo from './components/user-info/UserInfo.vue'
  import NetworkInfo from './components/network-info/NetworkInfo.vue'
  import OrderInfo from './components/order-info/OrderInfo.vue'
  import OperationLog from '@/components/pages/order/detail/pages/body/side-bar/OperationLog.vue'
  import Commodity from './components/commodity/Commodity.vue'
  import routeComponentName from '@/config/route-component-name'

  defineOptions({
    name: routeComponentName.order.historyOrderDetail,
  })

  // 操作日志组件实例
  const operationLogRef = ref<InstanceType<typeof OperationLog> | null>(null)

  /**
   * 更新日志记录
   */
  const updateOperationLog = () => {
    // if (operationLogRef.value) {
    // operationLogRef.value.getList(1)
    // }
  }

  // 是否显示侧边栏
  const isShowSideBar = ref(true)

  const route = useRoute()
  const orderDetail = ref(null) //工单详情
  const showAddServiceFeeWidthSpare = ref(false) // 是否显示申请服务项目与工单物料
  const loading = ref(false)
  const workNo = ref('')
  const getOrderDetailData = async () => {
    showAddServiceFeeWidthSpare.value = false
    loading.value = true
    const res = await getHistoryDetail(route.params.id)
    loading.value = false
    if (res.data.success) {
      orderDetail.value = res.data.data.row
      workNo.value = res.data.data.row.orderNo
      showAddServiceFeeWidthSpare.value = orderDetail.value.status === 3
    } else {
      ElMessage({
        showClose: true,
        message: res.data.message,
        type: 'error',
        duration: 3000,
      })
    }
  }

  onMounted(() => {
    if (route.params.id) {
      getOrderDetailData()
      updateOperationLog()
    }
  })
</script>

<style lang="scss" scoped>
  :deep(.el-collapse-item__arrow) {
    display: none;
  }

  .order_detail {
    width: 100%;
    height: calc(100vh - 90px);
    overflow: auto;
    box-sizing: border-box;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;

    .header {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      box-sizing: border-box;
      background-color: #fff;
      padding: 12px;
      .order_detail_header_status {
        display: flex;
        gap: 5px;
        align-items: center;

        .order_number_module {
          font-weight: bold;
          font-size: 14px;
        }

        .status {
          display: flex;
          gap: 5px;
        }
      }
    }

    .body {
      width: 100%;
      height: calc(100% - 64px);
      display: flex;
      gap: 12px;

      .content_container {
        width: calc(100%);
        position: relative;
        height: 100%;

        .content {
          height: 100%;
          overflow-y: auto;
          display: flex;
          flex-direction: column;
          gap: 12px;

          &::-webkit-scrollbar {
            display: none;
          }
        }

        .expand_collapse {
          position: absolute;
          z-index: 99;
          right: 0;
          top: 0;
          cursor: pointer;
          width: 18px;
          height: 32px;
          display: flex;
          align-items: center;
          justify-content: center;

          .show_btn_r {
            background-color: #fff;
            padding: 0 3px;
            box-shadow: 4px 0 4px 2px #e4e7ed;
            border-radius: 0 8px 8px 0;
            line-height: 32px;
            height: 32px;
            display: flex;
            justify-content: center;
            align-items: center;
          }

          .show_btn_l {
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #fff;
            padding: 0 3px;
            box-shadow: -4px 0 8px 2px #e4e7ed;
            border-radius: 8px 0 0 8px;
            line-height: 32px;
            height: 32px;
          }
        }

        .user_network_info {
          display: flex;
          gap: 12px;
          .network_info {
            background-color: #fff;
            padding: 16px;
            flex: 1;
          }
          .user_info {
            width: 30%;
            min-width: 200px;
            background-color: #fff;
            padding: 16px;
          }
        }

        .order_info {
          background-color: #fff;
          padding: 16px;
          width: calc(100% - 32px);
        }
      }

      // .sidebar {
      //   min-width: 360px;
      //   height: 100%;
      //   background-color: #fff;
      //   padding: 12px;
      //   box-sizing: border-box;
      // }
    }
  }

  :deep(.el-tag) {
    border: none;
  }

  .space {
    margin-top: 60px;
    position: relative;
  }

  .pt5 {
    padding-left: 20px;
    padding-right: 20px;
    padding-top: 5px;
  }

  .pt10 {
    padding-top: 10px;
  }

  .mt10 {
    margin-top: 10px;
  }

  .mb10 {
    margin-bottom: 10px;
  }

  .mt20 {
    margin-top: 20px;
  }

  .title {
    h4 {
      line-height: 30px;
      color: #333333;
      font-size: 15px;
    }
  }

  .title_bl {
    border-left: #007cff solid 3px;
    padding-left: 5px;
    font-size: 14px;
  }

  .ord_dis {
    display: flex;
    justify-content: center;
    align-items: center;

    .img {
      width: 14px;
      height: 14px;
      margin-left: 20px;
      cursor: pointer;
    }
  }

  :deep(.el-table) {
    .number {
      color: #007cff;
      cursor: pointer;

      &:hover {
        text-decoration: underline;
      }
    }

    .cell {
      // text-align: center;
      font-size: 12px;
    }

    //th.el-table__cell + th.el-table__cell {
    //  .cell {
    //    border-left: 1px solid #e7e3e3;
    //  }
    //}
  }

  .waiting_x {
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 2px;
    height: 14px;
    line-height: 12px;
    color: #ffffff;
    background-color: #e69103;
    cursor: pointer;
  }

  .waiting_pass {
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 2px;
    height: 14px;
    line-height: 12px;
    color: #ffffff;
    background-color: #a6a6a6;
    cursor: not-allowed;
  }

  .text-color {
    color: #007cff !important;

    &:hover {
      text-decoration: underline;
      cursor: pointer;
    }
  }

  .pagination {
    display: flex;
    margin-top: 10px;
    justify-content: end;
  }

  :deep(.el-tabs--border-card > .el-tabs__header) {
    .el-tabs__item {
      color: #000;
      font-size: 12px;
    }
  }

  .basic_information {
    padding: 12px 8px 0;

    :deep(.el-form-item__label) {
      color: #000000c9;
      font-size: 12px;
      height: 23px;
      line-height: 23px;
    }

    :deep(.el-form-item--default .el-form-item__content) {
      line-height: 23px;
    }

    .ml {
      font-size: 12px;
      color: #999;
    }

    .content_msg {
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      word-wrap: break-word;
      word-break: break-all;
    }
  }

  .right_side {
    margin-right: 12px;

    :deep(.el-tabs__item.is-active) {
      color: #007cff !important;
    }

    :deep(.el-tabs__nav-wrap::after) {
      height: 1px;
    }

    :deep(.el-tabs__nav .el-tabs__active-bar) {
      background-color: #007cff;
      padding: 0 10px;
      position: absolute;
      bottom: 0;
      left: -10px;
    }

    :deep(.el-tabs__nav .el-tabs__item:hover) {
      color: #007cff;
    }
  }

  .pro_dra {
    :deep(.el-input .el-input__wrapper) {
      box-shadow: 0 0 0 2px transparent;
      height: 40px;
      background-color: #f4f5f5;
      box-sizing: border-box;
    }

    :deep(.el-textarea__inner) {
      box-shadow: 0 0 0 2px transparent;
      background-color: #f4f5f5;
      font-size: 12px;
    }
  }

  :deep(.el-drawer__header) {
    margin-bottom: 0;
  }

  .ul_timeline {
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;

    /* IE 10+ */
    ::-webkit-scrollbar {
      display: none;
      /* Chrome Safari */
    }

    .first_pane {
      max-height: 72vh;
      overflow-y: auto;
    }
  }
</style>
